package xiaolong.zhou.spring_demo.Home;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import xiaolong.zhou.spring_demo.Pojo.Recharge;
import xiaolong.zhou.spring_demo.Pojo.UserDetail;
import xiaolong.zhou.spring_demo.Service.Users;
import xiaolong.zhou.spring_demo.Utils.Result;
import xiaolong.zhou.spring_demo.Utils.Token;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/home/user")
@ResponseBody
public class UserController {
    @Autowired
    private Users user;
    @GetMapping("/list")
    public Result lists(@RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer size,
                        String username, String phone,String email){
        return user.lists(page,size,username,phone,email);
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result show(@PathVariable("id") Integer id)
    {
        return user.show(id);
    }

    /**
     * 添加
     * @param relayUser
     * @return
     */
    @PostMapping("/store")
    public Result store(@RequestBody UserDetail relayUser ){
        return user.store(relayUser);
    }

    /**
     * 修改
     * @param relayUser
     * @return
     */
    @PutMapping("/save")
    public Result save(@RequestBody UserDetail relayUser){
        return user.save(relayUser);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return  user.delete(id);
    }

    @PostMapping("/recharge")
    public Result recharge(@RequestBody Recharge recharge, HttpServletRequest request){
        return user.recharge(recharge,request);
    }

}
